package com.bawei.mall.product.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.bawei.common.core.constant.EsConstant;
import com.bawei.common.core.domain.R;
import com.bawei.common.core.exception.ServiceException;
import com.bawei.common.core.utils.DateUtils;
import com.bawei.common.core.utils.bean.BeanUtils;
import com.bawei.common.rabbit.domain.Message;
import com.bawei.common.rabbit.enums.QueueEnum;
import com.bawei.common.security.auth.AuthUtil;
import com.bawei.common.security.utils.SecurityUtils;
import com.bawei.mall.product.cache.ProductInfoCache;
import com.bawei.mall.product.domain.MallProductBrandInfo;
import com.bawei.mall.product.domain.MallProductInfo;
import com.bawei.mall.product.domain.MallProductSkuInfo;
import com.bawei.mall.product.domain.model.ProductDetailModel;
import com.bawei.mall.product.domain.model.SkuModel;
import com.bawei.mall.product.domain.reponse.ProductDetailInfo;
import com.bawei.mall.product.domain.reponse.ProductInfoResponse;
import com.bawei.mall.product.domain.request.ProductInfoRequest;
import com.bawei.mall.product.mapper.MallProductInfoMapper;
import com.bawei.mall.product.service.*;
import com.bawei.mall.user.api.RemoteCusUserService;
import com.bawei.mall.user.domain.MallUserCollectInfo;
import com.bawei.mall.user.domain.model.CusLoginUser;
import com.bawei.system.domain.vo.EsDocInsertVo;
import com.bawei.system.remote.api.RemoteEsDocService;
import com.bawei.system.remote.api.RemoteEsIndexService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import javax.annotation.PostConstruct;
import java.util.*;

/**
 * 商品信息Service业务层处理
 *
 * @author DongZeLiang
 * @date 2022-09-19
 */
@Service
@Slf4j
public class MallProductInfoServiceImpl implements IMallProductInfoService {
    @Autowired
    private MallProductInfoMapper mallProductInfoMapper;

    @Autowired
    private IMallProductBrandInfoService mallProductBrandInfoService;

    @Autowired
    private IMallProductSkuInfoService skuInfoService;

    @Autowired
    private IMallProductRuleInfoService ruleInfoService;

    @Autowired
    private ProductInfoCache productInfoCache;

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Autowired
    private RemoteEsDocService remoteEsDocService;

    @Autowired
    private RemoteEsIndexService remoteEsIndexService;

    @Autowired
    private IMallProductTypeInfoService mallProductTypeInfoService;

    @Autowired
    private RemoteCusUserService remoteCusUserService;

    /**
     * 项目启动时，把商品数据初始化到ES中
     */
    @PostConstruct
    public void init() {
        loadingProductInfoToEs();
    }

    /**
     * 查询商品信息
     *
     * @param id 商品信息主键
     * @return 商品信息
     */
    @Override
    public ProductInfoResponse selectMallProductInfoById(Long id) {
        MallProductInfo mallProductInfo = mallProductInfoMapper.selectMallProductInfoById(id);
        ProductInfoResponse productInfoResponse = new ProductInfoResponse();
        BeanUtils.copyBeanProp(productInfoResponse, mallProductInfo);
        productInfoResponse.setSkuInfoList(
                skuInfoService.selectMallProductSkuInfoList(new MallProductSkuInfo() {{
                    setProductId(id);
                }})
        );
        return productInfoResponse;
    }
    @Override
    public ProductDetailInfo selectProductDetailsById(Long productId) {
        if (productId == null || productId == 0) {
            throw new ServiceException("查询商品信息，依据不合法！");
        }
        ProductDetailInfo productDetailsResponse = new ProductDetailInfo();
        MallProductInfo productInfo = mallProductInfoMapper.selectMallProductInfoById(productId);
        if (productInfo == null) {
            throw new ServiceException("查询商品信息，商品数据为空");
        }

        MallProductBrandInfo productBrandInfo = mallProductBrandInfoService.selectMallProductBrandInfoById(productInfo.getBrandId());
        if (productBrandInfo == null) {
            throw new ServiceException("查询商品品牌信息，商品品牌数据为空");
        }
        productDetailsResponse.setProduct(productInfo);
        productDetailsResponse.setBrand(productBrandInfo);
        //TODO 待优化
//        List<MallProductSkuInfo> mallProductSkuInfos = skuInfoService.selectMallProductSkuInfoList(productId);
//        if (mallProductSkuInfos == null || mallProductSkuInfos.size() == 0) {
//            throw new ServiceException("查询商品信息，SKU数据为空");
//        }
//        productDetailsResponse.setSkuList(mallProductSkuInfos);
//        MallProductRuleInfo ruleInfo = ruleInfoService.selectMallProductRuleInfoById(productInfo.getRuleId());
//        if (ruleInfo == null) {
//            throw new ServiceException("查询商品信息，规格数据为空");
//        }
//        productDetailsResponse.setProductRule(ruleInfo);
        return productDetailsResponse;
    }

    /**
     * 查询商品信息列表
     *
     * @param mallProductInfo 商品信息
     * @return 商品信息
     */
    @Override
    public List<MallProductInfo> selectMallProductInfoList(MallProductInfo mallProductInfo) {
        return mallProductInfoMapper.selectMallProductInfoList(mallProductInfo);
    }

    /**
     * 新增商品信息
     *
     * @param productInfoRequest 商品信息
     * @return 结果
     */
    @Override
    @Transactional
    public int insertMallProductInfo(ProductInfoRequest productInfoRequest) {
        productInfoRequest.setCreateBy(String.valueOf(SecurityUtils.getUserId()));
        productInfoRequest.setCreateTime(DateUtils.getNowDate());
        int i = mallProductInfoMapper.insertMallProductInfo(productInfoRequest);
        if (i == 0) {
            return i;
        }
        skuInfoService.batchInsertProductSku(
                SkuModel.builderSkuModel(productInfoRequest.getId(), productInfoRequest.getSkuInfoList())
        );

        // 给搜索系统发送消息需要进行搜索更新
        try {
            rabbitTemplate.convertAndSend(QueueEnum.PRODUCT_ADD.queueName(),
                    Message.builderMsg(productInfoRequest.getId()));
        } catch (ServiceException serviceException) {
            throw new ServiceException("给搜索系统发送消息需要进行搜索更新失败！");
        }
        return i;
    }

    /**
     * 修改商品信息
     *
     * @param productInfoRequest 商品信息
     * @return 结果
     */
    @Override
    @Transactional
    public int updateMallProductInfo(ProductInfoRequest productInfoRequest) {
        productInfoRequest.setUpdateBy(String.valueOf(SecurityUtils.getUserId()));
        productInfoRequest.setUpdateTime(DateUtils.getNowDate());
        int i = mallProductInfoMapper.updateMallProductInfo(productInfoRequest);
        if (i == 0) {
            //将商品信息推送至MQ，异步更新ES
            try {
                rabbitTemplate.convertAndSend(QueueEnum.PRODUCT_ADD.queueName(),
                        Message.builderMsg(productInfoRequest.getId()));
            } catch (ServiceException serviceException) {
                throw new ServiceException("给搜索系统发送消息需要进行搜索更新失败！");
            }
            return i;
        }
        skuInfoService.deleteMallProductSkuInfoByProductId(productInfoRequest.getId());
        skuInfoService.batchInsertProductSku(
                SkuModel.builderSkuModel(productInfoRequest.getId(), productInfoRequest.getSkuInfoList())
        );
        return i;
    }

    /**
     * 批量删除商品信息
     *
     * @param ids 需要删除的商品信息主键
     * @return 结果
     */
    @Override
    public int deleteMallProductInfoByIds(Long[] ids) {
        skuInfoService.deleteMallProductSkuInfoByProductIds(ids);
        for (Long id : ids) {
            // 延迟执行
            productInfoCache.delayRemove(id);
        }
        return mallProductInfoMapper.deleteMallProductInfoByIds(ids);
    }

    /**
     * 删除商品信息信息
     *
     * @param id 商品信息主键
     * @return 结果
     */
    @Override
    public int deleteMallProductInfoById(Long id) {
        return mallProductInfoMapper.deleteMallProductInfoById(id);
    }

    /**
     * 商品总条数
     *
     * @param mallProductInfo 商品查询
     * @return
     */
    @Override
    public Long selectMallProductInfoCount(MallProductInfo mallProductInfo) {
        return mallProductInfoMapper.selectMallProductInfoCount(mallProductInfo);
    }

    /**
     * 商品上下架
     *
     * @param id
     * @return
     */
    @Override
    public R uploadInfo(Long id) {
        //查询商品信息
        MallProductInfo mallProductInfo = mallProductInfoMapper.selectMallProductInfoById(id);
        if (mallProductInfo == null) {
            //点击上架改为1
            //点击下架改为0
            throw new ServiceException("商品信息不存在");
        }
        //TODO 调用ES查询商品是否上架
        //feignClient.uploadInfo(id,"index");
        //TODO 查询商品SKU信息

        //TODO 封装ES商品信息
        //TODO 调用ES上架商品
        return R.ok();
    }

    @Override
    public void loadingProductInfoToEs() {
        //查询所有商品信息
        List<MallProductInfo> mallProductInfos = mallProductInfoMapper.selectMallProductInfoList(new MallProductInfo());
        if (mallProductInfos == null || mallProductInfos.size() == 0) {
            log.info("暂无需要同步的商品");
        }
        //调用ES查询索引是否存在
        R<Boolean> indexExit = remoteEsIndexService.indexExit(EsConstant.INDEX_NAME);
        if (!indexExit.getData()) {
            log.info("mall_product索引不存在,调用ES服务创建索引");
            //创建索引
            R<Boolean> indexCreate = remoteEsIndexService.indexCreate(EsConstant.INDEX_NAME);
            if (indexCreate.getData() != null && indexCreate.getData()) {
                //批量同步商品信息到ES}
                //构建参数
                List<EsDocInsertVo> esDocInsertVo = builderProductInfoToEs(mallProductInfos);
                //调用ES服务批量插入文档
                R<Boolean> batchInsert = remoteEsDocService.batchInsertDocs(esDocInsertVo);
                if (batchInsert.getData()) {
                    log.info("批量同步商品信息到ES成功");
                }
            }else {
                log.info("初始化mall_product索引失败");
            }
        }

    }

    /**
     * 商品上下架
     *
     * @param id
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void onOffShelve(String id) {
        // 查询商品的spu信息
        MallProductInfo mallProductInfo = mallProductInfoMapper.selectMallProductInfoById(Long.valueOf(id));

        // 校验商品信息是否存在
        if (mallProductInfo == null) {
            throw new ServiceException("该商品信息不存在");
        }

        // 查询商品的sku信息
        List<MallProductSkuInfo> mallProductSkuInfos = skuInfoService.selectMallProductSkuInfoList(Long.valueOf(id));

        // 校验sku信息是否为空
        if (CollectionUtils.isEmpty(mallProductSkuInfos)) {
            throw new ServiceException("该商品下sku信息不存在");
        }

        // 切换商品的上下架状态并且在es中删除下架的商品
        Integer newStatus = mallProductInfo.getPublishStatus().equals(1) ? 0 : 1;
        mallProductInfo.setPublishStatus(newStatus);

        //判断该商品是上架状态还是下架状态
        boolean onOffShelve = newStatus.equals("1");
        mallProductInfoMapper.updateMallProductInfo(mallProductInfo);
        if (onOffShelve){
            // 检查商品索引是否存在
            R<Boolean> indexExit = remoteEsIndexService.indexExit(EsConstant.INDEX_NAME);
            if (!indexExit.getData()) {
                throw new ServiceException("该商品索引不存在");
            }

            //构建es所需要的数据结构
            List<EsDocInsertVo> esDocInsertVos = builderProductInfo2Es(mallProductInfo,mallProductSkuInfos);
            //批量插入
            remoteEsDocService.batchInsertDocs(esDocInsertVos);
        }
        if (!onOffShelve){
            // 检查商品索引是否存在
            R<Boolean> indexExit = remoteEsIndexService.indexExit(EsConstant.INDEX_NAME);
            if (!indexExit.getData()) {
                throw new ServiceException("该商品索引不存在");
            }
            //根据商品spuId查询出skuId 进行es删除
            List<MallProductSkuInfo> skuInfoList = selectMallProductInfoById(Long.valueOf(mallProductInfo.getId())).getSkuInfoList();
            skuInfoList.stream().forEach(skuInfo->{
                Long docsId = skuInfo.getId();
                //单删
                remoteEsDocService.deleteDocsById(String.valueOf(docsId));
            });
            //es批删
//            List<String> docsIds = selectMallProductInfoById(Long.valueOf(mallProductInfo.getId()))
//                    .getSkuInfoList()
//                    .stream()
//                    .map(skuInfo -> String.valueOf(skuInfo.getId()))  // 将Long型id转换为String
//                    .collect(Collectors.toList());  // 收集为List<String>
//            remoteEsDocService.batchDeleteDocs(docsIds);
        }
    }

    /**
     * 构建Es商品SPU信息
     * @param mallProductInfos
     * @return
     */
    private List<EsDocInsertVo> builderProductInfoToEs(List<MallProductInfo> mallProductInfos) {
        List<EsDocInsertVo> esDocInsertVos = new ArrayList<>();
        mallProductInfos.stream().forEach(mallProductInfo -> {
            EsDocInsertVo esDocInsertVo = new EsDocInsertVo();
            esDocInsertVo.setId(String.valueOf(mallProductInfo.getId()));
            esDocInsertVo.setIndexName(EsConstant.INDEX_NAME);
            //对象转为Map
            Map<String, Object> data = JSON.parseObject(JSON.toJSONString(mallProductInfo), Map.class);
            esDocInsertVo.setData(data);
            esDocInsertVos.add(esDocInsertVo);
        });
        return esDocInsertVos;
    }

    /**
     * 构建Es商品SKU信息
     * @return     */
    private List<EsDocInsertVo> builderProductInfo2Es(MallProductInfo mallProductInfo, List<MallProductSkuInfo> mallProductSkuInfos) {
        List<EsDocInsertVo> esDocInsertVos = new ArrayList<>();
        mallProductSkuInfos.stream().forEach(mallProductSkuInfo -> {
            EsDocInsertVo esDocInsertVo = new EsDocInsertVo();
            esDocInsertVo.setId(String.valueOf(mallProductSkuInfo.getId()));
            esDocInsertVo.setIndexName(EsConstant.INDEX_NAME);
            //对象转为Map 存储SKU信息
            Map<String, Object> data = JSON.parseObject(JSON.toJSONString(mallProductSkuInfo), Map.class);

            //关键字集合
            List<String> keywords = new ArrayList<>();
            keywords.add(mallProductInfo.getName());
            keywords.add(mallProductBrandInfoService.selectMallProductBrandInfoById(Long.valueOf(mallProductInfo.getBrandId())).getName());
            keywords.add(mallProductInfo.getDescription());
            data.put("keyword",keywords);

            //存储图册信息
            data.remove("image");
            List<String> images = new ArrayList<>();
            images.add(mallProductInfo.getPic());
            images.addAll(Arrays.asList(mallProductInfo.getAlbumPics().split(",")));
//            data.put("images",JSON.parseObject(JSON.toJSONString(images)));
            data.put("images",images);

            //存储SPU信息
            data.put("productName",mallProductInfo.getName());
            data.put("productDesc",mallProductInfo.getDescription());
            data.put("type",mallProductInfo.getProductCategoryId());
            data.put("brand",mallProductInfo.getBrandId());
            //转换字典值
            data.put("typeName",mallProductTypeInfoService.selectMallProductTypeInfoById(Long.valueOf(mallProductInfo.getProductCategoryId())).getName());
            data.put("brandName",mallProductBrandInfoService.selectMallProductBrandInfoById(Long.valueOf(mallProductInfo.getBrandId())).getName());

            esDocInsertVo.setData(data);
            esDocInsertVos.add(esDocInsertVo);
        });
        return esDocInsertVos;
    }


    /**
     * 根据商品品牌ID查询商品列表
     */
    @Override
    public List<MallProductInfo> selectMallProductInfoListByBrandId(int brandId, int pageNum, int pageSize) {
        return mallProductInfoMapper.selectMallProductInfoListByBrandId(brandId,pageNum,pageSize);
    }

    @Override
    public List<MallProductInfo> selectHotProductInfoList() {
        List<MallProductInfo> hotProducts = mallProductInfoMapper.selectHotProductInfoList();
        if (hotProducts.size() == 0){
            throw new ServiceException("暂无热门商品");
        }
        return hotProducts;
    }

    @Override
    public List<MallProductInfo> selectNewProductInfoList() {
        List<MallProductInfo> newProductInfoList = mallProductInfoMapper.selectNewProductInfoList();
        if (newProductInfoList.size() == 0){
            throw new ServiceException("暂无新品好物");
        }
        return newProductInfoList;
    }

    @Override
    public List<MallProductInfo> selectMallProductInfoByKeywords(String keywords) {
        return mallProductInfoMapper.selectMallProductInfoByKeywords(keywords);
    }

    /**
     * 获取商品详情
     * @param id
     * @return
     */
    @Override
    public ProductDetailModel getProductDetailInfo(Long id) {
        ProductDetailModel productDetailModel = new ProductDetailModel();
        MallProductInfo productInfo = mallProductInfoMapper.selectMallProductInfoById(id);
        if (productInfo == null) {
            throw new ServiceException("商品不存在");
        }
        MallProductBrandInfo productBrandInfo = mallProductBrandInfoService.selectMallProductBrandInfoById(productInfo.getBrandId());
        if (productBrandInfo == null) {
            throw new ServiceException("商品品牌不存在");
        }


        //获取死值
        ProductDetailModel productDetailInfo1 = getProductDetailInfo();
        productDetailModel.setProduct(productInfo);
        productDetailModel.setBrand(productBrandInfo);
        productDetailModel.setProductAttributeList(productDetailInfo1.getProductAttributeList());
        productDetailModel.setProductAttributeValueList(productDetailInfo1.getProductAttributeValueList());
        productDetailModel.setSkuStockList(productDetailInfo1.getSkuStockList());
        System.out.println("商品详情信息："+productDetailModel);
        return productDetailModel;
    }

    /**
     * 获取用户收藏信息
     * @return
     */
    public List<MallUserCollectInfo> selectCollectInfos() {
        //远程调用用户服务 查询用户收藏信息
        MallUserCollectInfo collect = new MallUserCollectInfo();
        //获取当前登录人信息
        CusLoginUser loginCusUser = AuthUtil.getLoginCusUser(SecurityUtils.getToken());
        collect.setMemberId(loginCusUser.getUserid());

        //获取个人收藏信息
        List<MallUserCollectInfo> mallUserCollectInfoList = remoteCusUserService.getAllCollectInfos().getData();

        return mallUserCollectInfoList;
    }

    /**
     * 商品收藏
     * @param id
     */
    @Override
    public void collectMallProductInfoById(String id) {
        //根据商品ID查询商品信息
        MallProductInfo mallProductInfo = mallProductInfoMapper.selectMallProductInfoById(Long.valueOf(id));
        if (mallProductInfo == null) {
            throw new ServiceException("商品信息不存在");
        }

        // 进行收藏，商品收藏人气+1 并且 添加至用户收藏信息
        log.info("=====用户ID："+SecurityUtils.getUserId());
        MallUserCollectInfo mallUserCollectInfo = new MallUserCollectInfo();
        if (SecurityUtils.getUserId() == null || SecurityUtils.getUserId() == 0){
            throw new RuntimeException("您还未登录,请尽快登录");
        }
        mallUserCollectInfo.setMemberId(SecurityUtils.getUserId());
        mallUserCollectInfo.setCreateBy(String.valueOf(SecurityUtils.getUserId()));
        mallUserCollectInfo.setProductName(mallProductInfo.getName());
        mallUserCollectInfo.setProductId(Integer.valueOf(Math.toIntExact(mallProductInfo.getId())));
        mallUserCollectInfo.setProductPic(mallProductInfo.getPic());
        mallUserCollectInfo.setProductSubTitle(mallProductInfo.getSubTitle());
        mallUserCollectInfo.setProductPrice(mallProductInfo.getPrice());
        mallProductInfoMapper.insertCollectInfo(mallUserCollectInfo);
    }

    /**
     * 获取商品sku信息
     * @return
     */
    private MallProductSkuInfo getProductSkuInfo(String productId) {
        //根据商品ID查询商品sku信息
        MallProductSkuInfo mallProductSkuInfo = skuInfoService.selectMallProductSkuInfoById(Long.valueOf(productId));

        if (mallProductSkuInfo == null) {
            throw new ServiceException("商品sku信息不存在");
        }


        return mallProductSkuInfo;
    }

    public ProductDetailModel getProductDetailInfo() {
        ProductDetailModel productDetailModel = new ProductDetailModel();

        String productAttributeList = "[\n" +
                "            {\n" +
                "                \"id\": 43,\n" +
                "                \"productAttributeCategoryId\": 3,\n" +
                "                \"name\": \"颜色\",\n" +
                "                \"selectType\": 0,\n" +
                "                \"inputType\": 0,\n" +
                "                \"inputList\": \"\",\n" +
                "                \"sort\": 100,\n" +
                "                \"filterType\": 0,\n" +
                "                \"searchType\": 0,\n" +
                "                \"relatedStatus\": 0,\n" +
                "                \"handAddStatus\": 1,\n" +
                "                \"type\": 0\n" +
                "            },\n" +
                "            {\n" +
                "                \"id\": 44,\n" +
                "                \"productAttributeCategoryId\": 3,\n" +
                "                \"name\": \"容量\",\n" +
                "                \"selectType\": 0,\n" +
                "                \"inputType\": 1,\n" +
                "                \"inputList\": \"16G,32G,64G,128G,256G,512G\",\n" +
                "                \"sort\": 0,\n" +
                "                \"filterType\": 0,\n" +
                "                \"searchType\": 0,\n" +
                "                \"relatedStatus\": 0,\n" +
                "                \"handAddStatus\": 0,\n" +
                "                \"type\": 0\n" +
                "            },\n" +
                "            {\n" +
                "                \"id\": 45,\n" +
                "                \"productAttributeCategoryId\": 3,\n" +
                "                \"name\": \"屏幕尺寸\",\n" +
                "                \"selectType\": 0,\n" +
                "                \"inputType\": 0,\n" +
                "                \"inputList\": \"\",\n" +
                "                \"sort\": 0,\n" +
                "                \"filterType\": 0,\n" +
                "                \"searchType\": 0,\n" +
                "                \"relatedStatus\": 0,\n" +
                "                \"handAddStatus\": 0,\n" +
                "                \"type\": 1\n" +
                "            },\n" +
                "            {\n" +
                "                \"id\": 46,\n" +
                "                \"productAttributeCategoryId\": 3,\n" +
                "                \"name\": \"网络\",\n" +
                "                \"selectType\": 0,\n" +
                "                \"inputType\": 1,\n" +
                "                \"inputList\": \"3G,4G,5G,WLAN\",\n" +
                "                \"sort\": 0,\n" +
                "                \"filterType\": 0,\n" +
                "                \"searchType\": 0,\n" +
                "                \"relatedStatus\": 0,\n" +
                "                \"handAddStatus\": 0,\n" +
                "                \"type\": 1\n" +
                "            },\n" +
                "            {\n" +
                "                \"id\": 47,\n" +
                "                \"productAttributeCategoryId\": 3,\n" +
                "                \"name\": \"系统\",\n" +
                "                \"selectType\": 0,\n" +
                "                \"inputType\": 1,\n" +
                "                \"inputList\": \"Android,IOS\",\n" +
                "                \"sort\": 0,\n" +
                "                \"filterType\": 0,\n" +
                "                \"searchType\": 0,\n" +
                "                \"relatedStatus\": 0,\n" +
                "                \"handAddStatus\": 0,\n" +
                "                \"type\": 1\n" +
                "            },\n" +
                "            {\n" +
                "                \"id\": 48,\n" +
                "                \"productAttributeCategoryId\": 3,\n" +
                "                \"name\": \"电池容量\",\n" +
                "                \"selectType\": 0,\n" +
                "                \"inputType\": 0,\n" +
                "                \"inputList\": \"\",\n" +
                "                \"sort\": 0,\n" +
                "                \"filterType\": 0,\n" +
                "                \"searchType\": 0,\n" +
                "                \"relatedStatus\": 0,\n" +
                "                \"handAddStatus\": 0,\n" +
                "                \"type\": 1\n" +
                "            }\n" +
                "        ]";


        String productAttributeValueList="[\n" +
                "            {\n" +
                "                \"id\": 457,\n" +
                "                \"productId\": 42,\n" +
                "                \"productAttributeId\": 43,\n" +
                "                \"value\": \"曜金黑,冰霜银\"\n" +
                "            },\n" +
                "            {\n" +
                "                \"id\": 458,\n" +
                "                \"productId\": 42,\n" +
                "                \"productAttributeId\": 45,\n" +
                "                \"value\": \"6.7英寸\"\n" +
                "            },\n" +
                "            {\n" +
                "                \"id\": 459,\n" +
                "                \"productId\": 42,\n" +
                "                \"productAttributeId\": 46,\n" +
                "                \"value\": \"5G\"\n" +
                "            },\n" +
                "            {\n" +
                "                \"id\": 460,\n" +
                "                \"productId\": 42,\n" +
                "                \"productAttributeId\": 47,\n" +
                "                \"value\": \"Android\"\n" +
                "            },\n" +
                "            {\n" +
                "                \"id\": 461,\n" +
                "                \"productId\": 42,\n" +
                "                \"productAttributeId\": 48,\n" +
                "                \"value\": \"4460mAh\"\n" +
                "            }\n" +
                "        ]";

        String skuStockListStr ="[\n" +
                "            {\n" +
                "                \"id\": 229,\n" +
                "                \"productId\": 42,\n" +
                "                \"skuCode\": \"202211040042001\",\n" +
                "                \"price\": 4999.00,\n" +
                "                \"stock\": 99,\n" +
                "                \"pic\": \"http://macro-oss.oss-cn-shenzhen.aliyuncs.com/mall/images/20221104/huawei_mate50_01.jpg\",\n" +
                "                \"lockStock\": 0,\n" +
                "                \"spData\": \"[{\\\"key\\\":\\\"颜色\\\",\\\"value\\\":\\\"曜金黑\\\"},{\\\"key\\\":\\\"容量\\\",\\\"value\\\":\\\"128G\\\"}]\"\n" +
                "            },\n" +
                "            {\n" +
                "                \"id\": 230,\n" +
                "                \"productId\": 42,\n" +
                "                \"skuCode\": \"202211040042002\",\n" +
                "                \"price\": 5499.00,\n" +
                "                \"stock\": 100,\n" +
                "                \"pic\": \"http://macro-oss.oss-cn-shenzhen.aliyuncs.com/mall/images/20221104/huawei_mate50_01.jpg\",\n" +
                "                \"lockStock\": 0,\n" +
                "                \"spData\": \"[{\\\"key\\\":\\\"颜色\\\",\\\"value\\\":\\\"曜金黑\\\"},{\\\"key\\\":\\\"容量\\\",\\\"value\\\":\\\"256G\\\"}]\"\n" +
                "            },\n" +
                "            {\n" +
                "                \"id\": 231,\n" +
                "                \"productId\": 42,\n" +
                "                \"skuCode\": \"202211040042003\",\n" +
                "                \"price\": 4999.00,\n" +
                "                \"stock\": 100,\n" +
                "                \"pic\": \"http://macro-oss.oss-cn-shenzhen.aliyuncs.com/mall/images/20221104/huawei_mate50_02.jpg\",\n" +
                "                \"lockStock\": 0,\n" +
                "                \"spData\": \"[{\\\"key\\\":\\\"颜色\\\",\\\"value\\\":\\\"冰霜银\\\"},{\\\"key\\\":\\\"容量\\\",\\\"value\\\":\\\"128G\\\"}]\"\n" +
                "            },\n" +
                "            {\n" +
                "                \"id\": 232,\n" +
                "                \"productId\": 42,\n" +
                "                \"skuCode\": \"202211040042004\",\n" +
                "                \"price\": 5499.00,\n" +
                "                \"stock\": 100,\n" +
                "                \"pic\": \"http://macro-oss.oss-cn-shenzhen.aliyuncs.com/mall/images/20221104/huawei_mate50_02.jpg\",\n" +
                "                \"lockStock\": 0,\n" +
                "                \"spData\": \"[{\\\"key\\\":\\\"颜色\\\",\\\"value\\\":\\\"冰霜银\\\"},{\\\"key\\\":\\\"容量\\\",\\\"value\\\":\\\"256G\\\"}]\"\n" +
                "            }\n" +
                "        ]";

        List<HashMap> productAttribute = JSONArray.parseArray(productAttributeList, HashMap.class);
        List<HashMap> productAttributeValue = JSONArray.parseArray(productAttributeValueList, HashMap.class);
        JSONArray skuStockList = JSONArray.parseArray(skuStockListStr);
        productDetailModel.setProductAttributeList(productAttribute);
        productDetailModel.setProductAttributeValueList(productAttributeValue);
        productDetailModel.setSkuStockList(skuStockList);
        log.info("productDetailModel:{}",productDetailModel);
        return productDetailModel;
    }
}
